<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:v-on="http://www.w3.org/1999/xhtml"
      xmlns:v-bind="http://www.w3.org/1999/xhtml">

	<head>

		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		<title>小K服务后台管理系统</title>
		<meta name="keywords" content="">
		<meta name="description" content="">

		<link rel="shortcut icon" href="../../../static/favicon.ico" th:href="@{/favicon.ico}">

		<link rel="stylesheet" type="text/css" href="../../../static/bootstrap/css/bootstrap.min.css" th:href="@{/bootstrap/css/bootstrap.min.css}" />
		<link rel="stylesheet" type="text/css" href="../../../static/plugins/iCheck/custom.css" th:href="@{/plugins/iCheck/custom.css}" />
		<link rel="stylesheet" type="text/css" href="../../../static/plugins/switchery/switchery.css" th:href="@{/plugins/switchery/switchery.css}" />
		<link rel="stylesheet" type="text/css" href="../../../static/plugins/layui/css/layui.css" th:href="@{/plugins/layui/css/layui.css}" />
		<link rel="stylesheet" type="text/css" href="../../../static/web/admin/css/font-awesome.css" th:href="@{/web/admin/css/font-awesome.css}" />
		<link rel="stylesheet" type="text/css" href="../../../static/web/admin/css/animate.css" th:href="@{/web/admin/css/animate.css}" />
		<link rel="stylesheet" type="text/css" href="../../../static/web/admin/css/style.css" th:href="@{/web/admin/css/style.css}" />

	</head>

	<body class="gray-bg">
		<div class="wrapper wrapper-content animated fadeInRight" id="body">
			<div class="row">
				<div class="col-sm-12">
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<h5><a href="repairClassify.html" th:href="@{/admin/repairClassify}">分类列表</a> 》<span th:text="${session.classify.title}">报修分类子类管理</span> <small>报修分类子类管理</small></h5>
						</div>
						<div class="ibox-content">
							<div class="row">
								<div class="col-sm-5 m-b-xs">

									<div class="btn-group" id="exampleToolbar" role="group">
										<button type="button" class="btn btn-outline btn-default" v-on:click="add">
                                        <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                                    </button>
										<button type="button" class="btn btn-outline btn-default" v-on:click="del(undefined)">
                                        <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                                    </button>
									</div>

								</div>
								<div class="col-sm-4 m-b-xs">
								</div>
								<div class="col-sm-3">
									<div class="input-group">
										<input type="text" v-model.trim="pageInfo.search" placeholder="请输入关键词" class="input-sm form-control"> <span class="input-group-btn">
                                        <button type="button" class="btn btn-sm btn-primary"  v-on:click="searchUser"> 搜索</button> </span>
									</div>
								</div>
							</div>
							<div class="">
								<table class="table table-hover table-bordered">
									<thead>
										<tr>
											<th style="width: 50px;">
                                                <input type="checkbox" class="i-checks" v-on:click="select" v-model="selectAll">
                                            </th>
											<th style="width: 100px;">子类名称</th>
											<th>子类内容说明</th>
											<th style="width: 100px;">操作</th>
										</tr>
									</thead>
									<tbody id="list">
										<tr v-for="(item,index) in list">
											<td>
                                                <input type="checkbox" v-bind:value="item.id" v-model="item.select" class="i-checks">
											</td>
											<td>{{item.title}}</td>
											<td>{{item.content}}</td>
											<td>
												<div class="btn-group">
													<button data-toggle="dropdown" class="btn btn-white dropdown-toggle">操作 <span class="caret"></span>
                                </button>
													<ul class="dropdown-menu">
														<li>
															<a href="javascript:void(0);" v-on:click="update(item)">修改子类信息</a>
														</li>
														<li class="divider"></li>
														<li>
															<a href="javascript:void(0);" class="font-bold" v-on:click="del(item)">删除子类</a>
														</li>
													</ul>
												</div>
											</td>
										</tr>
										<tr v-if="!list || list.length == 0" style="text-align: center;"><td colspan="4">没有更多内容</td></tr>
									</tbody>
								</table>
							</div>
							<div id="page"></div>
						</div>
					</div>
				</div>

			</div>

		</div>

        <div id="winLayer" style="display: none;margin: 0;padding:0 20px;">
            <form class="form-horizontal m-t" id="form">
                <input type="hidden" v-model="info.id"/>
                <div class="form-group">
                    <label class="col-md-3 control-label">分类名称</label>
                    <div class="col-md-9">
                        <input type="text" v-model.trim="info.title" class="form-control" placeholder="分类名称">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">内容提示</label>
                    <div class="col-md-9">
                        <textarea name="" rows="" v-model.trim="info.content" class="form-control" cols="" placeholder="内容提示（可选）" style="resize: none;"></textarea>
                        <span class="help-block m-b-none">提示用户可报修的具体内容</span>
                    </div>
                </div>
            </form>
        </div>
		<script src="../../../static/plugins/jquery.min.js" th:src="@{/plugins/jquery.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../static/bootstrap/js/bootstrap.min.js" th:src="@{/bootstrap/js/bootstrap.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../static/plugins/vuejs/vue.min.js" th:src="@{/plugins/vuejs/vue.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../static/plugins/layui/layui.js" th:src="@{/plugins/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../static/web/admin/js/content.js" th:src="@{/web/admin/js/content.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../static/plugins/switchery/switchery.js" th:src="@{/plugins/switchery/switchery.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../static/plugins/peity/jquery.peity.min.js" th:src="@{/plugins/peity/jquery.peity.min.js}" type="text/javascript" charset="utf-8"></script>
		<script src="../../../static/plugins/iCheck/icheck.min.js" th:src="@{/plugins/iCheck/icheck.min.js}" type="text/javascript" charset="utf-8"></script>
		<!--<script src="../../../static/web/js/demo/peity-demo.js" th:src="@{/web/js/demo/peity-demo.js}" type="text/javascript" charset="utf-8"></script>-->
        <script src="../../../static/URL.js" th:src="@{/URL.js}"></script>

        <script>
            layui.use(['layer', 'laypage', 'laydate'], function(){
                var layer = layui.layer //获得layer模块
                    ,laypage = layui.laypage //获得laypage模块
                    ,laydate = layui.laydate; //获得laydate模块
                //使用模块
                var app = new Vue({
                    el: '#body',
                    data: {
                        selectAll: false,
                        list: [],
                        pageInfo:{
                            page:1,
                            search: ""
                        }
                    },
                    methods: {
                        searchUser: function() {
                            this.loadPage(1);
                        },
                        select: function() {
                            for(var i = 0; i < this.list.length; i++) {
                                this.list[i].select = this.selectAll
                            }
                        },
                        add:function(){
                            win.addShow();
                        },
                        update:function(item){
                            win.info = item;
                            win.updateShow();
                        },
                        del:function(item){
                            var data = {id:[]};
                            var names = [];
                            if (item === undefined){
                                for(var i in this.list) {
                                    var item1 = this.list[i];
                                    if(item1.select) {
                                        data.id.push(item1.id);
                                        names.push(item1.title);
                                    }
                                }
                            }else {
                                data.id.push(item.id);
                                names.push(item.title);
                            }
                            if(names.length === 0){layui.layer.msg("没有选择要操作的条目", {time: 20000,btn: ['明白了']});return false;}
                            layui.layer.confirm('您确定要删除【' + names.join("、") + '】报修分类子类内容吗？子类删除后，其子类下属的报修单将一并删除', {
                                btn: ['确定删除', '取消'] //按钮
                            }, function() {
                                $.ajax({
                                    type: "post",
                                    data:data,
                                    url: "./Del",
                                    async: true,
                                    dataType: "json",
                                    success: function(data) {
                                        if(data.code === 0){
                                            app.loadPage(1);
                                        }else{
                                            layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                        }
                                    },
                                    error: function() {
                                        layui.layer.msg("加载错误");
                                    }
                                });
                            });
                        },
                        loadPage: function(page) {
                            if(page === undefined) {
                                // 重新加载当前页面
                            }else if(page * 1 < 1) {
                                this.pageInfo.page=1;
                            }else {
                                this.pageInfo.page=page;
                            }
                            $.ajax({
                                type: "get",
                                data:app.pageInfo,
                                url: "./List",
                                async: true,
                                dataType: "json",
                                success: function(data) {
                                    if (data.code === 0) {
                                        layui.layer.msg(data.msg);
                                        app.list = data.list;
                                        layui.laypage.render({
                                            elem: "page",
                                            count:data.count,
                                            limit:10,
                                            curr: data.pageCurr,
                                            groups: 10,
                                            jump: function(obj, first) {
                                                //得到了当前页，用于向服务端请求对应数据
                                                var curr = obj.curr;
                                                if(!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                                    app.loadPage(curr);
                                                }
                                            }
                                        });
                                    }else {
                                        layui.layer.msg(data.msg, {time: 20000, btn: ['明白了']});
                                    }
                                },
                                error:function () {
                                    layui.layer.msg("加载错误", {time: 5000, btn: ['明白了']});
                                }
                            });
                        }
                    }
                });
                app.loadPage(1);
                var win = new Vue({
                    el: '#winLayer',
                    data: {
                        info:{}
                    },
                    methods:{
                        addShow:function(){
                            this.info={};
                            var addWin = layer.open({
                                title: "添加报修子类",
                                type: 1,
                                area: ['400px', '400px'],
                                content: $("#winLayer"),
                                btn: ["添加", "取消"],
                                yes: function(index, layero) {
                                    var info = win.info;
                                    layui.layer.close(index);
                                    $.ajax({
                                        type: "post",
                                        data: info,
                                        url: "./Add",
                                        async: true,
                                        dataType: "json",
                                        success: function(data) {
                                            if(data.code === 0){
                                                app.loadPage(1);
                                            }else{
                                                layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                            }
                                        },
                                        error: function() {
                                            layui.layer.msg("加载错误");
                                        }
                                    });
                                }
                            });
                        },
                        updateShow:function(){
                            var addWin = layui.layer.open({
                                title: "修改报修子类",
                                type: 1,
                                area: ['400px', '400px'],
                                content: $("#winLayer"),
                                btn: ["修改", "取消"],
                                yes: function(index, layero) {
                                    var info = win.info;
                                    layui.layer.close(index);
                                    $.ajax({
                                        type: "post",
                                        data: info,
                                        url: "./Update",
                                        async: true,
                                        dataType: "json",
                                        success: function(data) {
                                            if(data.code === 0){
                                                app.loadPage(1);
                                            }else{
                                                layui.layer.msg(data.msg, {time: 20000,btn: ['明白了']},function(){app.loadPage(1);});
                                            }
                                        },
                                        error: function() {
                                            layui.layer.msg("加载错误");
                                        }
                                    });
                                }
                            });
                        }
                    }
                });
            });
		</script>
	</body>

</html>